﻿using System;

namespace ObserverPattern;

public static class Program
{
    public static void Main()
    {
        Console.WriteLine("观察者模式");
        SimpleImplement.Media tencent1 = new SimpleImplement.TencentGame("腾讯游戏", "一款新游发布！");
        var user11 = new SimpleImplement.Subscriber("小王");
        var user12 = new SimpleImplement.Subscriber("小李");
        // 添加订阅者
        tencent1.AddObserver(user11);
        tencent1.AddObserver(user12);
        tencent1.Update();
        Console.WriteLine("移除小李的订阅");
        tencent1.RemoveObserver(user12);
        tencent1.Update();
        
        Console.WriteLine("-----------------------------------");

        Console.WriteLine("观察者模式(委托)");
        DelegateImplement.Media tencent = new DelegateImplement.TencentGame("腾讯游戏", "一款新游发布！");
        var user21 = new DelegateImplement.Subscriber("小王");
        var user22 = new DelegateImplement.Subscriber("小李");
        tencent.AddObserver(user21.ReceiveAction);
        tencent.AddObserver(user22.ReceiveAction);
        tencent.Update();
        Console.WriteLine("移除小李的订阅");
        tencent.RemoveObserver(user22.ReceiveAction);
        tencent.Update();
    }
}